package com.gujiangbo.oom;

import sun.nio.ch.DirectBuffer;

import java.nio.ByteBuffer;

/**
 * @Author: gujiangbo.co
 * @Contact: 646832012@qq.com
 * @Date: 2022/3/12 20:10
 * @Version: 1.0
 * @Description: Direct buffer Memory
 * -Xms10m -Xmx10m -XX:+PrintGCDetails -XX:MaxDirectMemorySize=5m
 * <p>
 * 导致原因：
 * 写NIO程序经常使用ByteBuffer来读取或者写入数据
 */
public class JavaDirectBufferMemory {


    public static void main(String[] args) {
        // 默认使用本地内存为：本地/4 = 4G
        System.out.println("配置的maxDirectMemory" + (sun.misc.VM.maxDirectMemory() / (double) 1024 / 1024) + "MB");
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(6 * 1024 * 1024);

    }
}
